/**
 * 
 */
package fr.sportsurbains;

import java.util.List;
import java.util.Locale;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

/**
 * @author jshi
 *
 */
public class MyPagerAdapter extends PagerAdapter {

	List<View> mListViewPager;            //ViewPager对象的内容
	Context mContext;
	
	public MyPagerAdapter(Context Context, List<View> list) {
		this.mContext = Context;
		this.mListViewPager = list;
		//加载xml文件到ViewPager对象中
		
	}
	/* (non-Javadoc)
	 * @see android.support.v4.view.PagerAdapter#getCount()
	 */
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mListViewPager.size();
	}

	/* (non-Javadoc)
	 * @see android.support.v4.view.PagerAdapter#isViewFromObject(android.view.View, java.lang.Object)
	 */
	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == object;
	}
	
	public Object instantiateItem(View container, int position) {
		((ViewPager)container).addView(mListViewPager.get(position));
		return mListViewPager.get(position);
	}
	
	public CharSequence getPageTitle(int position) {
		Locale l = Locale.getDefault();
		switch (position) {
		case 0:
			return mContext.getString(R.string.title_section1).toUpperCase(l);
		case 1:
			return mContext.getString(R.string.title_section2).toUpperCase(l);
		case 2:
			return mContext.getString(R.string.title_section3).toUpperCase(l);
		case 3:
			return mContext.getString(R.string.title_section4).toUpperCase(l);
		}
		return null;
	}
	
	public void destroyItem(View container, int position, Object object) {
		((ViewPager)container).removeView(mListViewPager.get(position));
	}

}
